from rest_framework import serializers
from .models import Article


class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ['title', 'content', 'emotion', 'depressed', 'extreme', 'top', 'public', 'anonymous']

    def validate_title(self, title):
        if title is None or len(title) < 1 or len(title) > 30:
            return serializers.ValidationError("标题数据不合法")
        else:
            return title
